package com.yami.shop.api.controller;

import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.google.common.collect.Maps;
import com.yami.shop.bean.app.param.SendSmsParam;
import com.yami.shop.bean.enums.SendType;
import com.yami.shop.bean.event.BusinessAddMallSharePersonnftEvent;
import com.yami.shop.bean.model.BusinessNft;
import com.yami.shop.bean.model.VrSceneTrigger;
import com.yami.shop.common.bean.TencentSMS;
import com.yami.shop.common.config.Constant;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.config.ShopConfig;
import com.yami.shop.config.WxConfig;
import com.yami.shop.service.BusinessNftService;
import com.yami.shop.service.SmsLogService;
import com.yami.shop.service.SysConfigService;
import com.yami.shop.service.VrSceneTriggerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author LGH
 */
@RestController
@RequestMapping("/sms")
@Tag(name = "发送验证码接口")
public class SmsController {

    @Autowired
    private SmsLogService smsLogService;
    @Autowired
    private VrSceneTriggerService vrSceneTriggerService;
    @Autowired
    private WxConfig wxConfig;
    @Autowired
    private ShopConfig shopConfig;
    @Autowired
    private SysConfigService sysConfigService;
    @PostMapping("/sendLoginCode")
    @Operation(summary =  "发送登录验证码", description = "用户发送登录验证码")
    public ServerResponseEntity<Void> sendLoginCode(@RequestBody SendSmsParam sendSmsParam) {
        // 每个手机号每分钟只能发十个注册的验证码，免得接口被利用
        smsLogService.sendSms(SendType.LOGIN, sendSmsParam.getMobile(), sendSmsParam.getMobile(), Maps.newHashMap());
        return ServerResponseEntity.success();
    }

    @PostMapping("/sendCheckCode")
    @Operation(summary =  "发送验证码", description = "用户发送验证码")
    public ServerResponseEntity<Void> sendCheckCode(@RequestBody SendSmsParam sendSmsParam) {
        // 每个手机号每分钟只能发十个注册的验证码，免得接口被利用
        smsLogService.sendSms(SendType.VALID, sendSmsParam.getMobile(), sendSmsParam.getMobile(), Maps.newHashMap());
        return ServerResponseEntity.success();
    }

    @PostMapping("/sendUpdatePwdCode")
    @Operation(summary =  "发送修改密码验证码接口", description = "发送修改密码验证码接口")
    public ServerResponseEntity<Void> sendUpdatePwdCode(@RequestBody SendSmsParam sendSmsParam) {
        // 每个手机号每分钟只能发十个注册的验证码，免得接口被利用
        smsLogService.sendSms(SendType.UPDATE_PASSWORD, sendSmsParam.getMobile(), sendSmsParam.getMobile(), Maps.newHashMap());
        return ServerResponseEntity.success();
    }

    @PostMapping("/sendSetPayPwdCode")
    @Operation(summary =  "发送支付密码验证码接口", description = "发送支付密码验证码接口")
    public ServerResponseEntity<Void> sendSetPayPwdCode(@RequestBody SendSmsParam sendSmsParam) {
        // 每个手机号每分钟只能发十个注册的验证码，免得接口被利用
        smsLogService.sendSms(SendType.SET_PAY_PASSWORD, sendSmsParam.getMobile(), sendSmsParam.getMobile(), Maps.newHashMap());
        return ServerResponseEntity.success();
    }

    @PostMapping("/sendCancelCode")
    @Operation(summary =  "发送注销账号验证码接口", description = "发送注销账号验证码接口")
    public ServerResponseEntity<Void> sendCancelCode(@RequestBody SendSmsParam sendSmsParam) {
        // 每个手机号每分钟只能发十个注册的验证码，免得接口被利用
        smsLogService.sendSms(SendType.CANCEL, sendSmsParam.getMobile(), sendSmsParam.getMobile(), Maps.newHashMap());
        return ServerResponseEntity.success();
    }
}
